package cz.possoft.client.piskvorky.gui.components;

/**
  * Pomocne vlakno k vykreslovani pri pohybu mysi nad sachovnici 
  *  
  * @author mara
  */
public class PiskvorkyThread extends Thread {

	// pane nad kterym se vykresluje
	private PiskvorkyPane piskvorkyPane;

	// true pokud se bude vykreslovat
	private boolean repaintFlag;
	
	// Indikator ukonceneho vlakna
	private boolean endFlag;
	
	// sleep interval
	private static final int SLEEP_INTERVAL = 200;
	

	public PiskvorkyThread(PiskvorkyPane pane) {
		piskvorkyPane = pane;
		repaintFlag = false;
		endFlag = false;
		start();
	}

	public void run() {
		while (!endFlag) {
			try {
				sleep(SLEEP_INTERVAL);
			} catch (Exception e) {
				e.printStackTrace();
			}
			if (repaintFlag) {
				piskvorkyPane.repaint();
				repaintFlag = false;
			}
		}
	}

	public void setRepaintFlag(boolean repaintFlag) {
		this.repaintFlag = repaintFlag;
	}
	
	public void setEndFlag(boolean endFlag) {
		this.endFlag = endFlag;
	}

}
